﻿using apitest.Application.Entities.Pms;
using Furion.Logging;
using Furion.Logging.Extensions;
using System.Reflection;

namespace apitest.Application.Test.Services
{
    [DynamicApiController]
    public class Test10Service
    {

        ISqlSugarClient _db;
        ISqlSugarClient _t5db;
      
        public Test10Service(ISqlSugarClient db)
        {
            _db = db;
        }
        [HttpGet, QueryParameters]
        public async Task T1( )
        {
            ////var site = "岳池";
            //var site = "岳池";
            //var deviceList = await _db.Queryable<Production_Device>()
            //     .Where(o => o.Site == site&&o.Volume>0)
            //     .ToListAsync();
            //var excelList = MiniExcel.Query<T10Class > ("aaa.xlsx",   sheetName:site);

            //var CodeList1 = new List<T10Class>();
            //var CodeList2 = new List<T10Class>();

            //foreach (var item in excelList)
            //{
            //    await _db.Updateable<Production_Device>()
            //        .SetColumns(o => new Production_Device() { MonthDepreciation = item.MonthDepreciation })
            //        .Where(o => o.Site == site && o.Code == item.Code)
            //        .ExecuteCommandAsync();
            //}
            //return "";
            ////foreach (var item in deviceList)
            ////{
            ////    if (!excelList.Any(o => o.Code == item.Code && o.Volume == item.Volume))
            ////    {
            ////        CodeList1.Add(new T10Class()
            ////        {
            ////            Code = item.Code,
            ////            Volume = item.Volume,
            ////        });
            ////    }
            ////}

            ////foreach (var item in excelList)
            ////{
            ////    if (!deviceList.Any(o => o.Code == item.Code && o.Volume == item.Volume))
            ////    {
            ////        CodeList2.Add(item);
            ////    }
            ////}
            
            ////return new  {
            ////    CodeList1,
            ////    CodeList2
            ////};

        }

        public async Task<dynamic> DynamicSetValue()
        {
            var data= new Production_Device();
            //var type = data.GetType();
            //PropertyInfo[] properties = data.GetType().GetProperties();
            //foreach (var item in properties)
            //{
            //    FieldInfo fieldInfo = type.GetField(item.Name);
            //    if (fieldInfo != null) {
            //        Type fieldType = fieldInfo.FieldType;
            //    }

            //}
            Type type = data.GetType();

            PropertyInfo[] properties =type.GetProperties();
            foreach (var item in properties)
            {
                var a = item.PropertyType;
                Console.WriteLine($"{item.Name}========{item.PropertyType}");
                 
            }
            //FieldInfo[] fields = type.GetFields(); // 获取所有字段的FieldInfo数组
            //foreach (FieldInfo field in fields)
            //{
            //    var a = $"Field Name: {field.Name}, Field Type: {field.FieldType.FullName}";
            //    Console.WriteLine(a); // 输出每个字段的名称和类型
            //}
            return data;
        }


        public class T10Class
        {
            public string Code { get; set; }
            public int Volume { get; set; }
            public double MonthDepreciation { get; set; }
        }
    }
}
